package engine

import (
	"go.uber.org/zap"
	"gogogo-server/engine/lgconf"
	"gogogo-server/engine/module"
	"gogogo-server/engine/utils"
	"gogogo-server/engine/zlog"
	"log"
	"os"
	"os/signal"
)

func Run(cfgName string, mods ...module.IModule) {
	if err := utils.ParseYaml(cfgName, &lgconf.LGConfig); err != nil {
		log.Fatalf("解析配置:%s 出错:%s", cfgName, err)
	}
	log.Println(lgconf.LGConfig)
	if !zlog.InitLogger(&lgconf.LGConfig.LGLogCfg) {
		log.Fatal("初始化日志失败")
	}
	for _, m := range mods {
		module.Register(m)
	}
	if err := module.Init(); err != nil {
		zap.S().Fatal(err)
	}
	// close
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill)
	sig := <-c
	zap.S().Infof("收到结束进程信号:%v", sig)
	module.Destroy()
}
